package tech.aistar.controller;

import tech.aistar.entity.Color;
import tech.aistar.entity.Phone;
import tech.aistar.entity.PhoneDetail;
import tech.aistar.entity.Size;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

/**
 * @Author: lya
 * @Description: 本类的作用描述:
 * @CreateDate: 2019/9/8
 * @Version: 1.0
 */
@WebServlet("/phone/detailView")
public class PhoneDetailViewAction extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置文档类型
        resp.setContentType("text/html");
        //设置编码
        resp.setCharacterEncoding("UTF-8");
        //获取文档输出流
        PrintWriter out = resp.getWriter();

        //获取手机详细信息
        PhoneDetail phoneDetail = (PhoneDetail) req.getSession().getAttribute("phoneDetail");
        Phone phone = (Phone) req.getSession().getAttribute("phone");

        //获取手机颜色信息
        List<Color> colorList = (List<Color>) req.getSession().getAttribute("colorList");

        //获取手机尺寸信息
        List<Size> sizeList = (List<Size>) req.getSession().getAttribute("sizeList");

        out.println("<!DOCTYPE html>");
        out.println("<html lang='en'>");

        out.println("<head>");
        out.println("<meta charset='UTF-8'>");
        out.println("<meta name='viewport' content='width=device-width, initial-scale=1.0'>");
        out.println("<meta http-equiv='X-UA-Compatible' content='ie=edge'>");
        out.println("<title>手机详细信息页面 </title>");
        out.println("<!-- 引入bootstrap框架的样式文件 -->");
        out.println("<link rel='stylesheet' href='"+req.getContextPath()+"/plugins/bootstrap/css/bootstrap.css' type='text/css'>");
        out.println("<link rel='stylesheet' href='"+req.getContextPath()+"/css/phoneDetail.css' type='text/css'>");
        out.println("</head>");
        out.println("<body>");
        out.println("<!-- begin -->");
        out.println("<div class='container-fluid'>");
        out.println("   <div class='row'>");
        out.println("       <!-- 大图begin -->");
        out.println("       <div class='col-md-5' style='float: left; '>");
        out.println("           <div class='infopicture'>");

        out.println("           <img src='"+phone.getUrl()+"' style='width:432px; height:432px;'>");

        out.println("           </div>");
        out.println("       </div>");
        out.println("       <!-- 大图end -->");
        out.println("       <!-- 详情begin -->");
        out.println("       <div class='col-md-5' style='float: left;'>");
        out.println("           <!-- 标题begin -->");
        out.println("           <div class='title'>");
        out.println("           <h4> <b>"+phone.getName()+"</b> </h4>");
        out.println("           </div>");
        out.println("           <!-- 标题end -->");
        out.println("           <!-- 信息begin -->");
        out.println("           <div class='message'>");
        out.println("               <span>3200万AI自拍 超广角三摄 </span>");
        out.println("           </div>");
        out.println("           <!-- 信息end -->");
        out.println("           <!-- 价格begin -->");
        out.println("           <div class='price'>");
        out.println("               <div class='col-md-3'>");
        out.println("                   <div class='name'>");
        out.println("                       <span>价格 </span>");
        out.println("                   </div>");
        out.println("               </div>");
        out.println("               <div class='value'>");
        out.println("               <span>¥"+phone.getPrice()+" </span>");
        out.println("               </div>");
        out.println("           </div>");
        out.println("           <!-- 价格end -->");
        out.println("           <!-- 运费begin -->");
        out.println("           <div class='freight'>");
        out.println("               <div class='col-md-3'>");
        out.println("                   <div class='name'>");
        out.println("                       <span>运费 </span>");
        out.println("                   </div>");
        out.println("               </div>");
        out.println("               <div>");
        out.println("                   <form class='form-inline'>");
        out.println("                       <div data-toggle='distpicker'>");
        out.println("                           <div class='form-group'>");
        out.println("                               <label class='sr-only' for='province1'>Province</label>");
        out.println("                               <select class='form-control' id='province1'></select>");
        out.println("                           </div>");
        out.println("                           <div class='form-group'>");
        out.println("                               <label class='sr-only' for='city1'>City</label>");
        out.println("                               <select class='form-control' id='city1'></select>");
        out.println("                           </div>");
//        out.println("                           <div class='form-group'>");
//        out.println("                               <label class='sr-only' for='district1'>District</label>");
//        out.println("                               <select class='form-control' id='district1'></select>");
//        out.println("                           </div>");
        out.println("                       </div>");
        out.println("                   </form>");
        out.println("               </div>");
        out.println("           </div>");
        out.println("           <!-- 运费end -->");
        out.println("           <!-- 累计评价begin -->");
        out.println("           <div class='commentCount'>");
        out.println("               <div class='col-md-6 tatol'>");
        out.println("                   <span class='name'>累计评价 <a href='#' style='color: red'>"+ phoneDetail.getCommentCount()+" </a> </span>");
        out.println("               </div>");
        out.println("               <div class='integral'>");
        out.println("                   <span class='name'>送天猫积分 <a href='#' style='color: green'>159 </a>起 </span>");
        out.println("               </div>");
        out.println("           </div>");
        out.println("           <!-- 累计评价end -->");
        out.println("           <!-- 网络类型begin -->");
        out.println("           <div class='nettype'>");
        out.println("               <div class='col-md-3'>");
        out.println("                   <div class='name'>");
        out.println("                       <span>网络类型 </span>");
        out.println("                   </div>");
        out.println("               </div>");
        out.println("               <div class='col-md-9'>");
        out.println("                   <a href='#'>");
        out.println("                       <div class=' value'>");
        out.println("                           <span>4G全网通 </span>");
        out.println("                       </div>");
        out.println("                   </a>");
        out.println("               </div>");
        out.println("           </div>");
        out.println("           <!-- 网络类型end -->");
        out.println("           <!-- 手机颜色begin -->");
        out.println("           <div class='phonecolor'>");
        out.println("               <div class='col-md-3'>");
        out.println("                   <div class='name'>");
        out.println("                       <span>机身颜色 </span>");
        out.println("                   </div>");
        out.println("               </div>");
        out.println("               <div class='col-md-9'>");
        for (Color c : colorList) {

        }
        out.println("                   <a href='#'>");
        out.println("                       <div class='colorinfo'>");
        out.println("                           <img src='"+req.getContextPath()+"/imgs/red.jpg' alt=''>");
        out.println("                           <span>渐变红 </span>");
        out.println("                       </div>");
        out.println("                   </a>");
        out.println("               </div>");
        out.println("           </div>");
        out.println("           <!-- 手机颜色end -->");
        out.println("           <!-- 套餐类型begin -->");
        out.println("           <div class='set_meal'>");
        out.println("               <div class='col-md-3'>");
        out.println("                   <div class='name'>");
        out.println("                       <span>套餐类型 </span>");
        out.println("                   </div>");
        out.println("               </div>");
        out.println("               <div class='col-md-9'>");
        out.println("                   <a href='#'>");
        out.println("                       <div class='standard'>");
        out.println("                           <span>官方标配 </span>");
        out.println("                       </div>");
        out.println("                   </a>");
        out.println("               </div>");
        out.println("           </div>");
        out.println("           <!-- 套餐类型end -->");
        out.println("           <!-- 存储容量begin -->");
        out.println("           <div class='capacity'>");
        out.println("               <div class='col-md-3'>");
        out.println("                   <div class='name'>");
        out.println("                       <span>存储容量 </span>");
        out.println("                   </div>");
        out.println("               </div>");
        out.println("               <div class='col-md-9'>");
        out.println("                   <a href='#'>");
        out.println("                       <div class='capacitySize'>");
        out.println("                           <span>6+64GB </span>");
        out.println("                       </div>");
        out.println("                   </a>");
        out.println("               </div>");
        out.println("           </div>");
        out.println("           <!-- 存储容量end -->");
        out.println("           <!-- 数量begin -->");
        out.println("           <div class='count'>");
        out.println("               <div class='col-md-3'>");
        out.println("                   <div class='name'>");
        out.println("                       <span>数量 </span>");
        out.println("                   </div>");
        out.println("               </div>");
        out.println("               <div>");
        out.println("               <div class='col-md-3'> </div>");
        out.println("                   <span class='name'>件 </span>");
        out.println("               </div>");
        out.println("           </div>");
        out.println("           <!-- 数量end -->");
        out.println("           <!-- 购买添加begin -->");
        out.println("           <div class='buy_and_add'>");
        out.println("               <a href='#'>");
        out.println("                   <div class='col-md-5 buy'>");
        out.println("                       <span>立即购买 </span>");
        out.println("                   </div>");
        out.println("               </a>");
        out.println("               <a href='#'>");
        out.println("                   <div class='col-md-5 add'>");
        out.println("                       <span class='glyphicon glyphicon-shopping-cart'>加入购物车 </span>");
        out.println("                   </div>");
        out.println("               </a>");
        out.println("           </div>");
        out.println("           <!-- 购买添加end -->");
        out.println("       </div>");
        out.println("       <!-- 详情end -->");
        out.println("   </div>");
        out.println("</div>");
        out.println("<!-- end -->");

        out.println("<!-- bootstrap中的js插件依赖于jquery框架,所以必须先引入jquery的js文件 -->");
        out.println("<script src='"+req.getContextPath()+"/plugins/jquery/jquery.min.js'></script>");
        out.println("<!--引入bootstrap的js文件-->");
        out.println("<script src='"+req.getContextPath()+"/plugins/bootstrap/js/bootstrap.js'></script>");
        out.println("<script src='"+req.getContextPath()+"/plugins/bootstrap-date/js/distpicker.data.js'></script>");
        out.println("<script src='"+req.getContextPath()+"/plugins/bootstrap-date/js/distpicker.js'></script>");
        out.println("<script src='"+req.getContextPath()+"/plugins/bootstrap-date/js/main.js'></script>");
        out.println("<script src='"+req.getContextPath()+"/js/phoneDetail.js'></script>");
        out.println("</body>");

        out.println("</html>");

    }
}
